home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.0 KB | 216 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPrvRFl.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWPRVRFL_H
- #define FWPRVRFL_H
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWFILESP_H
- #include "FWFileSp.h"
- #endif
-
- #ifndef FWRESFI_K
- #include "FWResFil.k"
- #endif
-
- #ifndef FWCOUPTR_H
- #include "FWCouPtr.h"
- #endif
-
- #ifndef FWPRIEXC_H
- #include "FWPriExc.h"
- #endif
-
- #if defined(FW_BUILD_WIN) && !defined(__WINDOWS_H)
- #include <windows.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TYPES__)
- #include <Types.h>
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #if defined FW_BUILD_MAC
- typedef short FW_ResourceFileID;
- typedef Handle FW_ResourceHandle;
- #elif defined FW_BUILD_WIN
- typedef HINSTANCE FW_ResourceFileID;
- typedef HRSRC FW_ResourceHandle;
- #endif
-
- //========================================================================================
- // Exception codes for resources
- //========================================================================================
-
- const FW_PlatformError FW_xResourceFile = -30025;
- const FW_PlatformError FW_xResourceNotFound = -30026;
- const FW_PlatformError FW_xResourceNotLoaded = -30027;
- const FW_PlatformError FW_xResourceFileNotFound = -30028;
-
- //========================================================================================
- // CLASS FW_CPrivResourceFileRep
- //========================================================================================
- // This internal class is the reference counted representation class used by the
- // FW_CResourceFile class defined above.
-
- class FW_CLASS_ATTR FW_CPrivResourceFileRep : public FW_CCountedPtrRep
- {
- public:
- virtual ~ FW_CPrivResourceFileRep();
- // Closes the underlying resource file if necessary.
-
- FW_CPrivResourceFileRep(const FW_CFileSpecification& newFileSpec);
- // Open a resources file by name.
- // This instance assumes responsibility for closing the file.
-
- FW_CPrivResourceFileRep(FW_ResourceFileID resFileID);
- // Attach to a previously opened file.
- // This instance does not assume responsibility for closing the file.
-
- const FW_CFileSpecification* GetFileSpecification() const;
- // Get the file specificaiton for the resourcesFile.
-
- FW_Boolean HasResource(FW_ResourceId resourceId,
- FW_ResourceType resourceType) const;
- // Returns TRUE if the resource exists in the file, FALSE if it doesn't.
-
- FW_ResourceHandle GetResourceHandle(FW_ResourceId resourceId,
- FW_ResourceType resourceType) const;
- // Gets the resource handle. Resource data may still be purgeable or unloaded.
- // Client assumes responsibility to call ReleaseResourceHandle when done.
-
- void ReleaseResourceHandle(FW_ResourceHandle handle) const;
- // Releases the resource handle. All memory is released.
-
- FW_Boolean PrivHasSpecialResource(FW_ResourceId resourceId,
- FW_ResourceType resourceType) const;
- // Returns TRUE if the resource exists in the file, FALSE if it doesn't.
-
- FW_PlatformHandle PrivGetSpecialResource(FW_ResourceId resourceId,
- FW_ResourceType resourceType) const;
- // Gets the special resource handle.
- // It is the clients reponsibility to release the handle if necessary,
- // using whatever platform specific code is required.
-
- FW_ResourceFileID PrivGetResourceFileID();
- // Return the platforms's "file ID" for this resources file.
-
- protected:
-
- void ThrowExceptionIfResourceLoadError(
- FW_PlatformHandle resourceHandle,
- FW_ResourceId resourceId,
- FW_ResourceType resourceType) const;
- // The bottleneck from which resources exceptions are thrown.
-
- private:
-
- FW_ResourceHandle GetResource(FW_ResourceId resourceId,
- FW_ResourceType resourceType) const;
- // Attempt to load the resource, return NULL if failed.
-
- static FW_CFileSpecification GetFileSpecificationForID(FW_ResourceFileID resFileID);
- // Given a file ID, return the file spec for the file.
-
- static FW_ResourceFileID OpenResourceFile(const FW_CFileSpecification& fileSpec);
- // Attempts to open the file, throws exceptions on failure.
-
- static void CloseResourceFile(FW_ResourceFileID file);
- // Closes the file.
-
- FW_Boolean fMustCloseFile;
- // TRUE if this instance has assumed responsibility for closing the file.
-
- FW_ResourceFileID fResourceFileID;
- // The platform's file ID for the resources file.
-
- FW_CFileSpecification fFileSpec;
- // The file specificaiton for the resources file.
-
- private:
-
- FW_CPrivResourceFileRep(const FW_CPrivResourceFileRep&);
- // Don't allow copy construction
-
- FW_CPrivResourceFileRep& operator=(const FW_CPrivResourceFileRep&);
- // Don't allow copy by value
-
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivResourceFileRep::PrivGetResourceFileID()
- //----------------------------------------------------------------------------------------
-
- inline FW_ResourceFileID FW_CPrivResourceFileRep::PrivGetResourceFileID()
- {
- return fResourceFileID;
- }
-
- //========================================================================================
- // CLASS FW_PPrivResourceFile
- //========================================================================================
-
- class FW_CLASS_ATTR FW_PPrivResourceFile : public FW_CCountedPtr
- {
- public:
- FW_PPrivResourceFile();
- // Create a "NULL" FW_PPrivResourceFile
-
- FW_PPrivResourceFile(FW_CPrivResourceFileRep* privResourceFileRep);
- FW_PPrivResourceFile(const FW_PPrivResourceFile& privResourceFile);
- virtual ~ FW_PPrivResourceFile();
-
- FW_PPrivResourceFile& operator=(const FW_PPrivResourceFile& other);
- // Assignment, point this pointer to the same rep as the other pointer points to.
-
- // ----- Overload of accessors methods -----
- FW_CPrivResourceFileRep* operator->() const;
- FW_CPrivResourceFileRep& operator*() const;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_PPrivResourceFile::operator=
- //----------------------------------------------------------------------------------------
-
- inline FW_PPrivResourceFile& FW_PPrivResourceFile::operator=(const FW_PPrivResourceFile& other)
- {
- SetRep(other.fRep);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PPrivResourceFile::operator->
- //----------------------------------------------------------------------------------------
-
- inline FW_CPrivResourceFileRep* FW_PPrivResourceFile::operator->() const
- {
- return (FW_CPrivResourceFileRep*)fRep;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PPrivResourceFile::operator*
- //----------------------------------------------------------------------------------------
-
- inline FW_CPrivResourceFileRep& FW_PPrivResourceFile::operator*() const
- {
- return *((FW_CPrivResourceFileRep*)fRep);
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-